package com.yuntian.controller;

import com.yuntian.anno.Log;
import com.yuntian.pojo.Dept;
import com.yuntian.pojo.Emp;
import com.yuntian.pojo.Result;
import com.yuntian.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Update;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
   /* private static Logger log = LoggerFactory.getLogger(DeptController.class);  @SLF4j*/

    /*@RequestMapping(value = "/depts",method = RequestMethod.GET)//指定请求方式为get*/
    @GetMapping
    public Result list(){
        log.info("查询全部部门数据");
        //调用serivce来查询信息
        List<Dept> depts =  deptService.list();

       /* System.out.println("查询部门全部数据");*/
        return Result.success(depts);
    }
    @Log
    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据id删除一条数据:{}",id);
        //调用service去删除部门
        deptService.delete(id);//根据id删除部门数据
        return Result.success();
    }
    @Log
    @PostMapping
    public Result add(@RequestBody Dept dept){
        log.info("新增数据:{}",dept);
        deptService.add(dept);
        return Result.success();
    }

    @GetMapping("{id}")
    public Result SelectById(@PathVariable Integer id){
        log.info("根据:{}查数据",id);
        List<Dept> empList = deptService.SelectById(id);
        return Result.success(empList);
    }

    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("修改数据");
        deptService.updateData(dept);
        return Result.success();
    }

}
